package leetcode.bitarithmetic;

public class SingleNumber {
    class Solution1 {
        public int singleNumber(int[] nums) {
            int ans = 0;
            for (int num : nums) {
                ans ^= num;
            }
            return ans;
        }
    }

//
//    class Solution2 {
//        public int singleNumber(int[] nums) {
//
//        }
//    }

    class Solution3 {
        public int[] singleNumber(int[] nums) {
            int exor = 0;
            for (int num : nums) {
                exor ^= num;
            }
            int one = exor & (-exor);
            int a = 0;
            System.out.println(one);
            for (int num : nums) {
                if ((num & one) == 1) {
                    a ^= num;
                }
            }
            return new int[]{a, a ^ exor};
        }
    }
}
